﻿@using Think9.Models;
@{
    ViewBag.Title = "Add";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml";
}

<form class="layui-form">
    <input style="display:none" id="frm" value="@ViewBag.frm">
    <div class="layui-form-item" style='text-align: Left;'><span class="layui-word-tip">测试指标用于系统测试.可批量新建测试指标</span></div>
    <div class="layui-form-item">
        <label class="layui-form-label">指标分类</label>
        <div class="layui-input-block">
            @Html.DropDownList("IndexSort", (IEnumerable<SelectListItem>)ViewBag.SortList, "==请选择指标分类==", new Dictionary<string, object> { })
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">编码前缀</label>
        <div class="layui-input-block">
            <input type="text" name="IndexId" id="IndexId" placeholder="指标编码=前缀+序号，序号为大于0小于新建数量的整数" autocomplete="off" class="layui-input" lay-verify="required|id" maxlength="30">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">名称前缀</label>
        <div class="layui-input-block">
            <input type="text" name="IndexName" id="IndexName" placeholder="指标名称=前缀+序号，序号为大于0小于新建数量的整数" autocomplete="off" class="layui-input" lay-verify="required" maxlength="50">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">指标类型</label>
        <div class="layui-input-block">
            <select id="IndexDataType" name="IndexDataType" lay-filter="IndexDataType" lay-verify='required'>
                <option value="">==请选择==</option>
                @foreach (IndexDtaeTypeEntity item in ((IEnumerable<IndexDtaeTypeEntity>)ViewBag.DtaeTypeList))
                {
                    <option value="@item.TypeId">@item.TypeName</option>
                }
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">新建数量</label>
        <div class="layui-input-block">
            <input type="text" name="num" id="num" placeholder="1-99之间" autocomplete="off" class="layui-input" lay-verify="required|number" maxlength="2">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> </label>
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="add">批量新建</button>
        </div>
    </div>
</form>
<script>
    layui.use(["form", "exLayer", "exUtils"], function () {
        let form = layui.form;
        let layer = layui.layer;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let $ = layui.$;

        form.render(); //

        form.verify({
            id: function (value, item) {
                if (!new RegExp("^[a-zA-Z]+[a-zA-Z0-9]+$").test(value)) {
                    return '编码由英文字符和数字组成，并以字母开头，不得包含中文、空格及其他字符';
                }
            }
        });

        form.verify({
            name: function (value, item) {
                if (!new RegExp("^[\u4e00-\u9fa5_a-zA-Z0-9]+$").test(value)) {
                    return '名称由汉字、数字、字母、下划线组成，不得包含其他字符';
                }
            }
        });

        form.on("submit(add)", function (data) {
            exUtils.ajax("/SysTable/IndexBasic/BatchAdd2", "post", { model: data.field, num: $("#num").val() }, true).done(function (response) {
                exLayer.greenTickMsg(response.message, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    if ($("#frm").val() == 'list') {
                        $(window.parent.document).find('#search').click();//刷新
                    }
                });
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });
    });
</script>